
def list2dict(data):
    return {x:i for i,x in enumerate(data)}

elem_keep_time=7 #元素保留时间
elem_attach_interval=2.5 #计时器间隔
elem_attach_count=3 #计数器触发次数

elem_types=list2dict(['phy','wind','rock','fire','water','ice','thunder','grass'])
excited_elems=[3,4,5,6]

react_types=list2dict(['超载','超导','蒸发','融化','感电','扩散','结晶','燃烧','冻结'])
boost_react=[react_types[x] for x in ['蒸发','融化']]
fusion_react=[react_types[x] for x in ['超载','超导','感电','扩散']]

damage_types=['normal', 'thump', 'skill', 'burst']
prop_boost_dict={
    'hp': 'blk.prop.hp.const+=pdata',
    'atk': 'blk.damage.atk.const+=pdata',
    'def': 'blk.prop.def.const+=pdata',
    'hp_r': 'blk.prop.hp.rate+=pdata',
    'atk_r': 'blk.damage.atk.rate+=pdata',
    'def_r': 'blk.prop.def.rate+=pdata',
    'crit': 'blk.damage.crit.rate+=pdata',
    'crit_atk': 'blk.damage.crit.atk+=pdata',
    'master': 'blk.damage.elem.master+=pdata',
    'charge': 'blk.prop.charge+=pdata',
}

#react_dict={{3,4}:2, {3,5}:3, {3,6}:0, {3,7}:7, {4,5}:8, {4,6}:4, {5,6}:1}
react_dict={{elem_types[x[0]],elem_types[x[1]]}:react_types[x[2]] for x in [['fire','water','蒸发'],['fire','ice','融化'],
            ['fire','thunder','超载'],['fire','grass','燃烧'],['water','ice','冻结'],['water','thunder','感电'],['ice','thunder','超导']]}
react_nochg=[react_types[x] for x in ['蒸发','融化']]
react_cost_dict_nochg={(elem_types[x[0]],elem_types[x[1]]):x[2] for x in [['fire','water',2],['water','fire',0.5],['fire','ice',2],['ice','fire',0.5]]}
react_cost_dict={react_types[x[0]]:x[1] for x in [['超载',1],['超导',1],['扩散',0.5],['结晶',0.5]]}
react_boost_rate_nochg={(elem_types[x[0]],elem_types[x[1]]):x[2] for x in [['fire','water',1.5],['water','fire',2],['fire','ice',2],['ice','fire',1.5]]}
react_boost_rate={react_types[x[0]]:x[1] for x in [['超载',4],['超导',1],['扩散',1.2],['碎冰',3],['感电',2.4]]}
fusion_elem_types={react_types[x[0]]:elem_types[x[1]] for x in [['超载','fire'],['超导','thunder'],['扩散',0.5],['结晶',0.5]]}

def get_react_type(attach_type, atk_type):
    # 扩散
    if (atk_type==1 and attach_type in excited_elems) or (attach_type==1 and atk_type in excited_elems):
        return 5

    # 结晶
    if (atk_type == 1 and attach_type in excited_elems) or (attach_type == 1 and atk_type in excited_elems):
        return 6

    re_set={atk_type, attach_type}
    if re_set in react_dict:
        return react_dict[re_set]

    return -1

def get_react_cost(attach_type, atk_type):
    react_type=get_react_type(attach_type, atk_type)
    if react_type in react_nochg:
        return react_cost_dict_nochg[(atk_type, attach_type)]
    else:
        return react_cost_dict[react_type]

def get_react_boost(attach_type, atk_type, react_type):
    if react_type in react_nochg:
        return react_boost_rate_nochg[(atk_type, attach_type)]
    else:
        return react_boost_rate[react_type]

def get_react_level_rate(level):
    if react_type in react_nochg:
        return react_boost_rate_nochg[(atk_type, attach_type)]
    else:
        return react_boost_rate[react_type]

def reduce_elem(elem_amount, keep_time, pass_time):
    rest_amount=elem_amount
    rest_time=keep_time
    if pass_time>elem_amount*2.5:
        pass_time-=elem_amount*2.5
        rest_amount=0
        if pass_time>keep_time:
            rest_time=0
        else:
            rest_time=keep_time-pass_time
    else:
        rest_amount-=pass_time/2.5
    return rest_amount, rest_time

def to_rate(x):
    return x/100